Location_();
var user_name = getCookie("user_name");
$('.user_name').text(user_name);

if(user_name=="admin"){
	$('#edit_position').removeAttr('disabled');
	$('#edit_user_type').append($("<option></option>").attr("value", '1').text('管理员'));
}

$('.return_bth').click(function() {
	$('.view_pop').css('display', 'none')
})

$('#cancel').click(function() {
	$('.motifi').css('display', 'none')
})
if(user_name=="admin"){
	$('.add_department_btn,.add_position_btn').removeClass('hide')
}

//网谈table
layui.use(['table', 'jquery', 'layer', 'form', 'element'], function() {
	var element = layui.element;
	var form = layui.form;
	var $ = layui.$ //重点处
		,
		layer = layui.layer;
	var table = layui.table;
	//监听表格复选框选择

	table.render({
		elem: '#LAY_table_userAdmin',
		response: {
			dataName: 'data.result',
			statusCode: 200
		},
		url: "http://"+com_url+"//admin/getUserList",
		cols: [
			[{
				fixed: 'left',
				checkbox: true,
				width: '5%'
			}, {
				field: 'name',
				width: '18%',
				title: '用户名',
			}, {
				field: 'positionName',
				width: '20%',
				title: '岗位',
			}, {
				field: 'zxh',
				width: '10.8%',
				title: '坐席号',
			}, {
				field: 'sexs',
				width: '10%',
				title: '性别',
			}, {
				field: 'status_name',
				width: '14%',
				title: '状态',
			}, {
				field: 'client_kw',
				width: '17%',
				toolbar: '#barDemo1',
				title: '操作',
			}]
		],
		even: true,
		page: true,
		limit: 10,
		id: 'LAY_tabled',
		done: function(res, count, curr) { //回调函数
			var perm = res.perm;
			var code = res.code;
			if(code==204){
				clearCookie();
				window.parent.top.location.reload();
			}
			if(perm.length=="2"){
				$('.ogani_admin').removeClass('hide')
			}
		}
	});

	//监听工具条
	table.on('tool(userAdmin)', function(obj) {
		var data = obj.data;
		var adminName = data.name;
		var sex = data.sexs;
		var position_name = data.positionName;
		var seats_num = data.zxh;
		var phone = data.telephone;
		var email = data.email;
		var address = data.address;
		var status = data.status;
		var status_name;
		if(status == "1") {
			status_name = "已激活"
		}
		if(status == "2") {
			status_name = "未激活"
		}
		if(status == "3") {
			status_name = "停用"
		}
		if(obj.event === 'detail') {
			layer.open({
				type: 1, //页面层
				title: '查看基本信息',
				area: '400px',
				skin: 'add_department_content',
				content: '<div class="departent_div">用户名&emsp;：<input type="text" value="' + adminName + '" /><br>性别&emsp;&emsp;：<input type="text" value="' + sex + '" /><br>手机&emsp;&emsp;：<input type="text" value="' + phone + '" /><br>坐席号&emsp;：<input type="text" value="' + seats_num + '" /><br>目前职位：<input type="text" value="' + position_name + '" /><br>邮箱&emsp;&emsp;：<input type="text" value="' + email + '" /><br>审核状态：<input id="status" type="text" value="' + status_name + '" /><br>联系地址：<input type="text" value="' + address + '" /></div>',
			})
		} else if(obj.event === 'edit') { //点击编辑
			var edit_department_id = obj.data.department_id;
			var edit_positonId = obj.data.position_id;
			var userName = obj.data.name;
			var category_id = obj.data.category_id;
			var status = obj.data.status;
			var zxhdq = obj.data.zxhdq;
			var sex = obj.data.sex;
			var email = obj.data.email;
			var zxhdq = obj.data.zxhdq;
			var zxh = obj.data.zxh;
			var floor = obj.data.floor;
			var telephone = obj.data.telephone;
			var address = obj.data.address;
			var edit_user_id = obj.data.user_id;
			var workNumber = obj.data.workNumber;
			$('#edit_name').val(userName);
			$('#telephone').val(telephone);
			$('#edit_address').val(address);
			$('#zxh').val(zxh);

			$('#edit_email').val(email);
			$('#word_num').val(workNumber);
			//判断用户类型
			if(category_id = category_id) {
				$("#edit_user_type option[value=" + category_id + "] ").attr("selected", true);
				form.render('select');
			}
			//判断激活状态
			// if(status = status) {
			// 	$("#status_num option[value=" + status + "] ").attr("selected", true);
			// 	form.render('select');
			// }
			var status_numDemo = '<option value="1">已激活</option>' +
				'<option value="2">未激活</option>' +
				'<option value="3">停用</option>';
				$('#status_num').append(status_numDemo);
				$("#status_num option[value=" + status + "] ").attr("selected", true);
				// form.render('select');
			var edit_user_typeDome = '<option value="2">员工</option>' +
				'<option value="3">新员工</option>';
				$('#edit_user_type').append(edit_user_typeDome);
				$("#edit_user_type option[value=" + category_id + "] ").attr("selected", true);
			// form.render('select');
			var floors = '<option value="3">3楼</option>' +
				'<option value="4">4楼</option>'+
				'<option value="6">6楼</option>';
				$('#floor').append(floors);
				$("#floor option[value=" + floor + "] ").attr("selected", true);
				
			var zxdq_typeDome = '<option value="1">七陌</option>' +
				'<option value="2">华翔</option>';
				$('#zxhdq').append(zxdq_typeDome);
				$("#zxhdq option[value=" + zxhdq + "] ").attr("selected", true);
				form.render('select');
				var sex_demo = '<input id="boy" type="radio" name="sex" value="1" title="男">' +
				'<input id="girl" type="radio" name="sex" value="2" title="女">'+
				'<input id="Donkown_" type="radio" name="sex" value="0" title="未知">';
				$('#sex_demo').append(sex_demo);
			//判断性别
			if(sex == '1') {
				$("#boy").attr("checked", 'checked');
				form.render();
			} else if(sex == "2") {
				$("#girl").attr("checked", 'checked');
				form.render();
			} else if(sex == "0") {
				$("#Donkown_").attr("checked", 'checked');
				form.render();
			}
			//判断楼层
			// if(floor == floor) {
			// 	$("#floor option[value=" + floor + "] ").attr("selected", true);
			// 	form.render();
			// }
			$.ajax({
				type: "get",
				beforeSend: cookie_val_fun,
				url: "http://"+com_url+"//admin/getBranchList",
				success: function(res) {
					var data = JSON.parse(res);
					var department_list = data.data;
					var code = data.code;
					// $("#edit_department option").empty();
					$("#edit_department").find('option').remove().end();
					// console.log(data)
					if(code == "200") {
						//渲染部门
						var edit_department = $("#edit_department");
						// edit_department.append($("<option></option>").attr("value", '').text('--请选择--'));
						$.each(department_list, function(key, role) { //遍历  
							edit_department.append($("<option ></option>").attr("value", role.department_id).text(role.name));
							form.render('select')
						});
						if(edit_department_id == edit_department_id) {
							$("#edit_department option[value=" + edit_department_id + "] ").attr("selected", true);
							form.render('select');
						}
					}
				},
			});

			$.ajax({
				type: "get",
				beforeSend: cookie_val_fun,
				data: {
					department_id: edit_department_id
				},
				url: "http://"+com_url+"/admin/getBranchPosition",
				success: function(res) {
					var data = JSON.parse(res).data;
					$("#edit_position option").empty();
					var edit_position = $('#edit_position');
					edit_position.find('option').remove().end();
					$.each(data, function(key, roles) { //遍历  
						edit_position.append($("<option></option>").attr("value", roles.position_id).text(roles.name));
					});
					if(edit_positonId == edit_positonId) {
						$("#edit_position option[value=" + edit_positonId + "] ").attr("selected", true);
						form.render('select');
					}
					form.render('select')
				},
			});

			layer.open({
				type: 1,
				title: '编辑基本信息',
				content: $('#revision'),
				area: '600px',
				btn: ['保存', "取消"],
				btn1: function(index, curr) {
					var rd = $("input[type='radio']:checked").val();
					$.ajax({
						type: "post",
						beforeSend: cookie_val_fun,
						data: {
							user_id: edit_user_id,
							name: $('#edit_name').val(),
							password: $('#edit_password').val(),
							category_id: $('#edit_user_type option:selected').val(),
							status: $('#status_num option:selected').val(),
							department_id: $('#edit_department option:selected').val(),
							position_id: $('#edit_position option:selected').val(),
							zxhdq: $('#zxhdq option:selected').val(),
							workNumber: $('#word_num').val(),
							sex: $("input[type='radio']:checked").val(),
							zxh: $('#zxh').val(),
							floor: $('#floor option:selected').val(),
							telephone: $('#telephone').val(),
							address: $('#edit_address').val(),
							email: $('#edit_email').val()
						},
						url: "http://"+com_url+"/admin/editUserInfo",
						success: function(res) {
							var data = JSON.parse(res);
							var code = data.code;
							let msg = data.msg;
							// $('#status_num').find('option').remove().end();
							if(code == "200") {
								$(".layui-laypage-btn")[0].click();
								layer.close(index);
								layer.msg(msg, {
									icon: 1
								});
								$('#status_num,#edit_user_type,#floor,#zxhdq').find('option').remove().end();
								$('#sex_demo').text("");
							} else {
								layer.msg(msg, {
									icon: 0
								})
							}
						},
						error: function(res) {
							layer.msg("数据库异常", {
								icon: 0
							})
						}
					});
				},
				btn2: function(index, curr) {
					$('#status_num,#edit_user_type,#floor,#zxhdq').find('option').remove().end();
					$('#sex_demo').text("");
				},
				cancel:function(){
					$('#status_num,#edit_user_type,#floor,#zxhdq').find('option').remove().end();
					$('#sex_demo').text("");
				}
			});
		}
		$('.departent_div input').attr('disabled', 'disabled')
	});
	//搜索功能
	var $ = layui.$,
		active = {
			reload_sbm: function() {
				var index = layer.load(1, {
					shade: [0.5, '#fff'] //0.1透明度的白色背景
				});
				var seach_department_id = $('#seach_department option:selected').val();
				var userName_val = $('#userName_val').val();
				//执行重载
				table.reload('LAY_tabled', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						department_id: seach_department_id,
						name: userName_val,
					},
					done: function(res) {
						layer.close(index);
					}

				});
			},
			//添加部门弹出层内容
			add_department: function() {
				if(user_name=="admin"){
					$.ajax({
						type: "get",
						beforeSend: cookie_val_fun,
						url: "http://"+com_url+"//admin/getBranchList",
						success: function(res) {
							var data = JSON.parse(res);
							var department_list = data.data;
							var code = data.code;
							if(code = "200") {
								layer.open({
									type: 1,
									title: '添加部门',
									area: '400px',
									skin: 'add_department_content', //给弹出层添加类名
									content: '<div>部门名称：<input id="add_department_input" class="department_input" type="text" value="" /><br>下级部门：<select class="top_department_class" id="top_department_id"></select></div>',
									btn: ['保存', '取消'],
									btnAlign: 'c',
									yes: function(index, layero) {
										var department_name_val = $('#add_department_input').val();
										var top_deparment_val = $('#top_department_id option:selected').val();
										if(department_name_val) {
											$.ajax({
												type: "post",
												beforeSend: cookie_val_fun,
												data: {
													name: department_name_val,
													parent_id: top_deparment_val
												},
												url: "http://"+com_url+"//admin/addBranch",
												success: function(res) {
													var data = JSON.parse(res);
													var codes = data.code;
													if(codes = "200") {
														layer.close(index);
														layer.msg("添加部门成功", {
															icon: 1
														})
													} else {
														layer.msg("数据异常", {
															icon: 0
														})
													}
												}
											});
										} else {
											layer.msg("请填写部门名称", {
												icon: 0
											})
										}
									}
								});
								var top_department = $(".top_department_class");
								$.each(department_list, function(key, role) { //遍历  
									top_department.append($("<option ></option>").attr("value", role.department_id).text(role.name));
								});
							}
	
						},
						error: function(res) {
							layer.msg("数据库异常", {
								icon: 0
							});
						}
					});
				}
			},
			//添加岗位弹出层
			add_position: function() {
				if(user_name=="admin"){
					$.ajax({
						type: "get",
						beforeSend: cookie_val_fun,
						data: {
							parent_id: 1
						},
						url: "http://"+com_url+"//admin/getBranchList",
						success: function(res) {
							var data = JSON.parse(res);
							var department_list = data.data;
							var code = data.code;
							if(code == "200") {
								//渲染部门
								var top_department = $(".top_department");
								$.each(department_list, function(key, role) { //遍历  
									top_department.append($("<option ></option>").attr("value", role.department_id).text(role.name));
								});
							} else {
								layer.msg("数据异常", {
									icon: 0
								})
							}
						},
						error: function(res) {
							layer.msg("数据库异常", {
								icon: 0
							})
						}
					});
					$.ajax({
						type: "get",
						beforeSend: cookie_val_fun,
						url: "http://"+com_url+"/admin/getPositionList",
						success: function(res) {
							var data = JSON.parse(res);
							var position_list = data.data;
							var code = data.code;
							if(code == "200") {
								//渲染岗位
								var top_position = $(".top_position");
								$.each(position_list, function(key, role) { //遍历  
									top_position.append($("<option ></option>").attr("value", role.position_id).text(role.name));
								});
							} else {
								layer.msg("数据异常", {
									icon: 0
								})
							}
						},
						error: function(res) {
							layer.msg("数据库异常", {
								icon: 0
							})
						}
					});
					layer.open({
						type: 1, //页面层
						title: '添加岗位',
						area: '400px',
						skin: 'add_department_content',
						content: '<div>岗位名称：<input id="add_positionName" class="department_input" type="text" value="" /><br>所属部门：<select lay-search="" class="top_department"></select><br>上级岗位：<select class="top_position"></select></div>',
						btn: ['保存', '取消'],
						btnAlign: 'c',
						yes: function(index, curr) {
							var add_positionName = $('#add_positionName').val();
							var add_DepartmentId = $('.top_department option:selected').val();
							var add_positionId = $('.top_position option:selected').val();
							if(add_positionName) {
								$.ajax({
									type: "post",
									beforeSend: cookie_val_fun,
									data: {
										name: add_positionName,
										department_id: add_DepartmentId,
										parent_id: add_positionId
									},
									url: "http://"+com_url+"/admin/addPosition",
									success: function(res) {
										var data = JSON.parse(res);
										var code = data.code;
										if(code == "200") {
											layer.msg("修改岗位成功", {
												icon: 1
											})
											layer.close(index)
										} else {
											layer.msg("数据异常", {
												icon: 0
											})
										}
									},
									error: function(res) {
										layer.msg("数据库异常", {
											icon: 0
										})
									}
								});
							} else {
								layer.msg("请填写岗位名称", {
									icon: 0
								})
							}
						}
					})
				}
			},
			//添加用户
			add_Users: function() {
				$.ajax({
					type: "get",
					beforeSend: cookie_val_fun,
					url: "http://"+com_url+"//admin/getBranchList",
					success: function(res) {
						var data = JSON.parse(res);
						var department_list = data.data;
						var code = data.code;
						if(code == "200") {
							//渲染部门
							var add_user_department = $(".add_user_departments");
							add_user_department.append($("<option></option>").attr("value", '').text('--请选择--'));
							$.each(department_list, function(key, role) { //遍历  
								add_user_department.append($("<option ></option>").attr("value", role.department_id).text(role.name));
								form.render('select')
							});
						}else{
							layer.msg("数据库异常", {
											icon: 0
										})
						}
					},
				});
				layer.open({
					type: 1,
					title: '添加用户',
					area: '400px',
					skin: 'add_department_content',
					content: '<div id="add_user_form" class="layui-form">用户名称：<input id="add_user_name" type="text" value="" /><br>密码&emsp;&emsp;：<input id="user_password" type="password" value="" /><br>坐席地区：<select id="zxdq"><option value="广东">广东</option></select><br>坐席号&emsp;：<input id="zxh_num" type="text" value="" /><br>工号&emsp;&emsp;：<input id="word_nums" type="text" value="" /><br>坐席楼层：<select id="floor_num"><option value="3">3楼</option><option value="4">4楼</option><option value="6">6楼</option></select><br><br>用户类别：<select id="user_type" name="interest" lay-filter="aihao"><option value="2">员工</option><option value="3">新员工</option></select><br><br>部门&emsp;&emsp;：<select lay-search="" name="department" class="add_user_departments"  lay-filter="user_select_value"></select><br><br>岗位&emsp;&emsp;：<select name="position" class="add_user_position" lay-filter="add_user_position"></select></div>',
					btn: ['保存', '取消'],
					btn1: function(index, layero) {
						var user_departmentVal = $('.add_user_departments option:selected').val();
						var user_positionVal = $('.add_user_position option:selected').val();
						console.log(user_positionVal)
						var add_user_name = $('#add_user_name').val();
						var user_password = $('#user_password').val();
						var zxdq = $('#zxdq option:selected').val();
						var user_type = $('#user_type option:selected').val();
						var zxh_num = $('#zxh_num').val();
						var word_num = $('#word_nums').val();
						var floor_num = $('#floor_num option:selected').val();
						if(add_user_name && user_departmentVal && user_positionVal && user_password && zxdq && user_type && zxh_num && word_num && floor_num) {
							$.ajax({
								type: 'post',
								beforeSend: cookie_val_fun,
								data: {
									name: add_user_name,
									password: user_password,
									zxhdq: zxdq,
									zxh: zxh_num,
									workNumber: word_num,
									floor: floor_num,
									category_id: user_type,
									department_id: user_departmentVal,
									position_id: user_positionVal
								},
								url: "http://"+com_url+"/admin/addUserInfo",
								success: function(res) {
									var code = JSON.parse(res).code;
									if(code = "200") {
										layer.close(index);
										$(".layui-laypage-btn")[0].click();
										layer.msg("添加用户成功", {
											icon: 1
										});
									} else {
										layer.msg("数据异常", {
											icon: 0
										});
									}
								},
								error: function() {
									layer.msg("数据异常", {
										icon: 0
									});
								}
							});
						} else {
							layer.msg("请认真填写，所有选项都不能为空", {
								icon: 0
							})
						};

					},
					btn2: function(index, curr) {
					}
				})
				if(user_name=="admin"){
					$('#user_type').append($("<option></option>").attr("value", '1').text('管理员'));
				}
				form.render('select'); //渲染部门select   add_user_position
			},
		
			//点击组织架构
			ogani_content:function(){
				$.ajax({
					type: "get",
					beforeSend: function(request) {
						request.setRequestHeader("ApiAuth", cookie_val);
					},
					url: "http://"+com_url+"//admin/structure",
					success: function(res) {
						var data = JSON.parse(res).data;
						$('.ogani_content').html(data);
						$('#browser').treeview()
						$(function() {
							$(".treeview .file").hover(function() {
								rel = $(this).attr('rel');
								ids = $(this).attr('id');
								$('#control_file' + rel).show();
							}, function() {
								rel = $(this).attr('rel');
								$('#control_file' + rel).hide();
								$('.permission,.position_delete,.position_edit').css('color', 'red')
							});
							$(".treeview .folder").hover(function() {
								rel = $(this).attr('rel');
								$('#control_folder' + rel).show();
							}, function() {
								rel = $(this).attr('rel');
								$('#control_folder' + rel).hide();
							});
							$("#check_all").click(function() {
								$("input[class='check_list']").prop('checked', $(this).prop("checked"));
							});
							$("#add_department").click(function() {
								$('#dialog-message2').dialog('open');
								$('#dialog-message2').load('{:U("user/department_add")}');
							});
							$("#add_role").click(function() {
								$('#dialog-message3').dialog('open');
								$('#dialog-message3').load('{:U("user/role_add")}');
							});
							$(".user").click(function() {
								$('#dialog-message5').dialog('open');
								$id = $(this).attr('rel');
								$('#dialog-message5').load('{:U("user/user_role_relation","by=role_user&role_id=")}' + $id);
							});
							//鼠标触摸颜色
							$(".permission,.position_delete,.position_edit").hover(function() {
								$(this).css('color', 'blue')
							})
							//点击修改
							$(".position_edit").click(function() {
								id = $(this).attr('id'); //部门
								rel = $(this).attr('rel'); //岗位
								layer.open({
									type: 1, //页面层
									title: '修改岗位信息',
									area: ['400px', '300px'],
									skin: 'add_department_content',
									content: '<div class="layui-form">岗位名称：<input id="add_positionNames" class="department_input" type="text" value="" /><br>所属部门：<select lay-search="" class="top_department"  lay-filter="edit_departmentValsb"></select><br>上级岗位：<select class="top_position"></select></div>',
									btn: ['保存', '取消'],
									btnAlign: 'c',
									yes: function(index, curr) {
										var add_positionName = $('#add_positionNames').val();
										var add_DepartmentId = $('.top_department option:selected').val();//部门
										var add_positionId = $('.top_position option:selected').val();//上级岗位
										if(add_positionName) { 
											$.ajax({
												type: "post",
												beforeSend: cookie_val_fun,
												data: {
													parent_id: add_positionId,
													name: add_positionName,
													department_id: add_DepartmentId,
													position_id: rel
												},
												url: "http://"+com_url+"/admin/editPosition",
												success: function(res) {
													var data = JSON.parse(res);
													var code = data.code;
													if(code == "200") {
														layer.msg("修改岗位成功", {
															icon: 1
														})
														layer.close(index);
														window.location.reload();
													} else {
														layer.msg("数据异常", {
															icon: 0
														})
													}
												},
												error: function(res) {
													layer.msg("数据库异常", {
														icon: 0
													})
												}
											});
										} else {
											layer.msg("请填写岗位名称", {
												icon: 0
											})
										}
									}
								})
								$.ajax({
									type: "get",
									beforeSend: cookie_val_fun,
									data: {
										department_id: id
									},
									url: "http://"+com_url+"//admin/getBranchList",
									success: function(res) {
										var data = JSON.parse(res);
										var department_list = data.data;
										var code = data.code;
										if(code == "200") {
											//渲染部门、授权
											var top_department = $(".top_department");
											$.each(department_list, function(key, role) { //遍历  
												top_department.append($("<option ></option>").attr("value", role.department_id).text(role.name));
											});
											$(".top_department option[value=" + id + "] ").attr("selected", true);
											form.render('select')
										}
									},
									error: function(res) {
										layer.msg("数据库异常", {
											icon: 0
										})
									}
								});
								//渲染岗位
								$.ajax({
									type: "get",
									beforeSend: cookie_val_fun,
									data: {
										department_id: id
									},
									url: "http://"+com_url+"/admin/getPositionList",
									success: function(res) {
										var data = JSON.parse(res).data;
										$("#edit_position option").empty();
										var edit_position = $('.top_position');
										edit_position.find('option').remove().end();
										$.each(data, function(key, roles) { //遍历  
											edit_position.append($("<option></option>").attr("value", roles.position_id).text(roles.name));
										});
										$.ajax({
											type: "get",
											beforeSend: cookie_val_fun,
											data: {
												position_id: rel
											},
											url: "http://"+com_url+"/admin/getPositionInfoOne",
											success: function(res) {
												var data = JSON.parse(res).data;
												var parent_id = data.parent_id;
												var Name = data.name
												setTimeout(function() {
													$('#add_positionNames').val(Name)
												}, 100)
												$(".top_position option[value=" + parent_id + "] ").attr("selected", true);
												form.render('select')
											},
										});
			
									},
								});
			
								form.on('select(edit_departmentValsb)', function(data) {
									var user_departmentId = data.value;
									$.ajax({
										type: "get",
										beforeSend: cookie_val_fun,
										data: {
											department_id: user_departmentId
										},
										url: "http://"+com_url+"/admin/getBranchPosition",
										success: function(res) {
											var data = JSON.parse(res).data;
											$(".top_position option").empty();
											var top_position = $(".top_position");
											top_position.find('option').remove().end();
											$.each(data, function(key, roles) { //遍历  
												top_position.append($("<option></option>").attr("value", roles.position_id).text(roles.name));
											});
											form.render('select')
										},
									});
								});
							});
							//点击授权按钮
							$(".permission").click(function() {
								id = $(this).attr('rel');
								var jsons;
								var arry = [];
								$.ajax({
									type: "get",
									beforeSend: cookie_val_fun,
									data: {
										rel: id
									},
									url: "http://"+com_url+"//admin/perm",
									success: function(res) {
										var data = JSON.parse(res);
										jsons = data.data;
										var xtree1 = new layuiXtree({
											elem: 'xtree1',
											form: form,
											data: jsons,
											ckall: true,
										});
										layer.open({
											type: 1,
											title: '授权信息',
											area: '400px',
											offset: 's',
											content: $('#tests'),
											btn: ['保存', '取消'],
											btn1: function(index, curr) {
												var oCks = xtree1.GetChecked();
												for(var i = 0; i < oCks.length; i++) {
													arry.push(oCks[i].value)
												}
												$.ajax({
													type: "post",
													beforeSend: cookie_val_fun,
													data: {
														rel: id,
														perm: arry
													},
													url: "http://"+com_url+"//admin/editPerm",
													success: function(res) {
														var data = JSON.parse(res);
														var code = data.code;
														if(code == "200") {
															layer.close(index)
															layer.msg("授权成功", {
																icon: 1
															})
														} else {
															layer.msg("数据异常", {
																icon: 0
															})
														}
													},
												});
											}
										})
			
									},
								});
							});
							//点击删除按钮
							$(".position_delete").click(function() {
								id = $(this).attr('rel');
							});
						});
					}
				});
			}
		
		};
		

	//搜索部门
	$.ajax({
		type: "get",
		beforeSend: cookie_val_fun,
		url: "http://"+com_url+"//admin/getBranchList",
		success: function(res) {
			var data = JSON.parse(res);
			var department_list = data.data;
			var code = data.code;
			if(code == "200") {
				//渲染部门
				var add_user_department = $(".add_user_department");
				add_user_department.append($("<option></option>").attr("value", '').text('--请选择--'));
				$.each(department_list, function(key, role) { //遍历  
					add_user_department.append($("<option ></option>").attr("value", role.department_id).text(role.name));
					form.render('select')
				});

			}
		},
	});
	//点击添加用户部门select
	form.on('select(user_select_value)', function(data) {
		var user_departmentId = data.value;
		$.ajax({
			type: "get",
			beforeSend: cookie_val_fun,
			data: {
				department_id: user_departmentId
			},
			url: "http://"+com_url+"/admin/getBranchPosition",
			success: function(res) {
				var data = JSON.parse(res).data;
				$(".add_user_position option").empty();
				var add_user_position = $('.add_user_position');
				add_user_position.find('option').remove().end();
				$.each(data, function(key, roles) { //遍历  
					add_user_position.append($("<option></option>").attr("value", roles.position_id).text(roles.name));
				});
				form.render('select')
			},
		});
	});
	//点击编辑用户部门select
	form.on('select(edit_departmentVal)', function(data) {
		var user_departmentId = data.value;
		$.ajax({
			type: "get",
			beforeSend: cookie_val_fun,
			data: {
				department_id: user_departmentId
			},
			url: "http://"+com_url+"/admin/getBranchPosition",
			success: function(res) {
				var data = JSON.parse(res).data;
				$("#edit_position option").empty();
				var edit_position = $('#edit_position');
				edit_position.find('option').remove().end();
				$.each(data, function(key, roles) { //遍历  
					edit_position.append($("<option></option>").attr("value", roles.position_id).text(roles.name));
				});
				form.render('select')
			},
		});
	});

	$('.layui-btn').on('click', function() {
		var type = $(this).data('type');
		active[type] ? active[type].call(this) : '';
	});
	$('.ogani_admin').on('click', function() {
		var type = $(this).data('type');
		active[type] ? active[type].call(this) : '';
	});
	//添加````````````弹出层按钮
	$('#add_btn li').on('click', function() {
		var type = $(this).data('type');
		active[type] ? active[type].call(this) : '';
	});
	
	if(getPicTabNum){
			$('.layui-tab-title li').eq(getPicTabNum).trigger('click')
	}

});